public class Test12 {
    //懒汉模式
    static class Single{
        private Single(){}
        volatile private static Single instance = null;
        public static Single getInstance(){
            if (instance == null){
                synchronized (Single.class){
                    if(instance == null){
                        instance = new Single();
                    }
                }
            }
            return instance;
        }
        private int fun(){
            return 1;
        }
    }

    public static void main(String[] args) {
        Single single = Single.getInstance();
        System.out.println(single);
        Single single2 = Single.getInstance();
        System.out.println(single2);
    }
}
